import logging


def get_logger(file_path):
    # 获取日志文件
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)

    # 设置输出格式
    fmt = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s", "%Y%b%d-%H:%M:%S")

    # 设置 控制台 处理器
    sh = logging.StreamHandler()
    sh.setFormatter(fmt)
    logger.addHandler(sh)

    # 设置 文件 处理器
    fh = logging.FileHandler(file_path)
    fh.setFormatter(fmt)
    logger.addHandler(fh)
    return logger


def set_moduls_logger(logger):
    """ 各个模型设置日志 """
    from .. import dataprocess
    from .. import models
    from .. import optimizer
    from .. import tokenizer

    dataprocess.set_logger(logger)
    models.set_logger(logger)
    optimizer.set_logger(logger)
    tokenizer.set_logger(logger)

